package com.itelite.domain.pojo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * @author 沈洋 邮箱:1845973183@qq.com
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User implements Serializable, UserDetails {

    private Integer userId;
    private String username;
    @JsonIgnore
    private transient String password;
    private Date createDate;
    private Integer status;
    @NotBlank(message = "角色不能为空")
    private String roles;
    @NotBlank(message = "真实姓名不能为空")
    private String realName;
    private String studentId;
    @NotNull(message = "组编号不能为空")
    private Integer groupId;
    private String email;
    private String mobile;
    private String qq;
    @NotNull(message = "性别不能为空")
    private Integer gender;
    private List<GrantedAuthority> authorities;
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }
    public void setAuthorities(List<GrantedAuthority> authorities) {
        this.authorities = authorities;
    }
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return status==1;
    }
}
